package com.woniuxy.contractsign.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.woniuxy.commons.annotation.RequirePerms;
import com.woniuxy.commons.entity.ContractSign;
import com.woniuxy.commons.entity.PageBean;
import com.woniuxy.commons.stafflog.LogRequirePerms;
import com.woniuxy.commons.utils.ResponseResult;
import com.woniuxy.contractsign.service.ContractSignService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xyq
 * @create 2021-11-10 11:05
 */
@RestController
@RequestMapping("/contractsign")
public class ContractSignController {

    @Resource
    private ContractSignService contractSignService;

    //删除合同签署的方法
    @LogRequirePerms(module = "",description = "删除合同信息")
    @RequirePerms("user:del")
    @DeleteMapping("/delContractSign/{consignid}")
    public ResponseResult<ContractSign> logdelContract(@PathVariable("consignid") int consignid){
        contractSignService.delectContractSignByid(consignid);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setCode(200);
        responseResult.setMessage("删除成功");
        return responseResult;
    }



    //得到所有的员工方法(分页)
    @LogRequirePerms(module = "",description = "查询所有合同信息")
    @RequirePerms("user:select")
    @GetMapping("/getallContractSign")
    @SentinelResource(value = "get",fallback = "fallbackgetallContractSign")
    public ResponseResult<PageBean<ContractSign>> loggetAllContractSign(ContractSign contractSign, int pageIndex, int pageSize){

        System.out.println(contractSign);

        List<ContractSign> contractSigns = contractSignService.selectAllContractSignByPage(contractSign, pageIndex, pageSize);
        int i = contractSignService.selectContractCountSignByPage(contractSign);
        PageBean<ContractSign> pageBean=new PageBean<>();
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(i);
        pageBean.setBeanList(contractSigns);
        ResponseResult<PageBean<ContractSign>> responseResult=new ResponseResult();
        responseResult.setCode(200);
        responseResult.setMessage("查询成功");
        responseResult.setData(pageBean);
        return responseResult;
    }

    //查询所有的降级的方法
    public ResponseResult<ContractSign> fallbackgetallContractSign(ContractSign contractSign,int pageIndex,int pageSize){
        ResponseResult responseResult=new ResponseResult();
        responseResult.setCode(500);
        responseResult.setMessage("系统维护中");
        return responseResult;
    }









}
